package com.yodawnla.easyPuyo.HUD;

import org.anddev.andengine.entity.sprite.Sprite;

import com.yodawnla.easyPuyo.system.Fonts;
import com.yodawnla.easyPuyo.system.Tex;
import com.yodawnla.lib.YoActivity;
import com.yodawnla.lib.util.widget.YoButton;
import com.yodawnla.lib.util.widget.YoText;

public class Window extends Hud
{
	protected YoText mText;
	protected Sprite mWindow;
	protected IButtonClickListener mListener;
	
	public static class Param
	{
		public String mText = "";
		public IButtonClickListener mListener = null;
		public String mOkBtnText = "Ok";
		public String mCancelBtnText = "Cancel";
		
		public int mX = 40; //(480-400/2)
		public int mY = 250;
	}
	
	YoButton mBg;
	public Window(String hudName, int zIndex)
	{
		super(hudName, zIndex);
		
		mBg = new YoButton(mHud, 0, 0, 480, 800, YoActivity.getBaseActivity().getTexture(Tex.White));
		mBg.setColor(0, 0, 0);
		mBg.setAlpha(0.7f);
		mLayer.attachChild(mBg);
		
		mWindow = new Sprite(0, 0, YoActivity.getBaseActivity().getTexture(Tex.Window));
		mWindow.setPosition(240 - mWindow.getWidth()/2, 250);
		mLayer.attachChild(mWindow);
		
		mText = new YoText(45, 45, Fonts.White20, 100);
		mWindow.attachChild(mText);
	}
	
	public void setBgVisible(boolean visible)
	{
		if (mBg != null)
			mBg.setVisible(visible);
	}
	
	public void show(String text)
	{
		show(text, null);
		CharacterStateHud.getInstance().setButtonsEnabled(false);
		mBg.setTouchAreaEnabled(false);
		mBg.setTouchAreaEnabled(true);
	}
	
	public void show(String text, IButtonClickListener listener)
	{
		mWindow.setPosition(40, 250);
		mListener = listener;
		mText.setText(text);
		super.show();
		CharacterStateHud.getInstance().setButtonsEnabled(false);
		mBg.setTouchAreaEnabled(false);
		mBg.setTouchAreaEnabled(true);
	}
	
	public void show(Param param)
	{
		mWindow.setPosition(param.mX, param.mY);
		mListener = param.mListener;
		mText.setText(param.mText);
		super.show();
		CharacterStateHud.getInstance().setButtonsEnabled(false);
		mBg.setTouchAreaEnabled(false);
		mBg.setTouchAreaEnabled(true);
	}
	
	public void hide()
	{
		CharacterStateHud.getInstance().setButtonsEnabled(true);
		super.hide();
		setBgVisible(true);
	}

	public interface IButtonClickListener
	{
		public void onOkClicked();
		public void onCancelClicked();
	}
}
